package dataStructure;

import java.util.ArrayList;
import java.util.Stack;

public class stack<e> {
    final private Integer maxsize = 50;

    ArrayList<e> data = new ArrayList<>();

    private int top;

    public stack() {
        this.top = -1;
    }

    public Boolean StackEmpty() {
        if (top == -1) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 入栈
     *
     * @param c
     * @return
     */
    public Boolean Push(e c) {
        if (top == maxsize - 1) {
            return false;
        }
        top++;
        data.add(top,c);
        return true;
    }


    public e Pop(){
        if (StackEmpty()) {
            throw new NegativeArraySizeException();
        }
        e x = data.get(top);
        top--;
        return x;
    }

    public e GetPop(){
        if (StackEmpty()){
            throw new NegativeArraySizeException();
        }
        return data.get(top);
    }
}
